/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            adminPayFeeDetailInfo: {
                fees: [],
                total: 0,
                records: 1,
                moreCondition: false,
                title: '',
                primeRates: [],
                feeConfigDtos: [],
                states: [],
                feeTypeCds: [],
                floors: [],
                communitys: [],
                totalReceivableAmount: 0.0,
                totalReceivedAmount: 0.0,
                allReceivableAmount: 0.0,
                allReceivedAmount: 0.0,
                totalPreferentialAmount: 0.0,
                totalDeductionAmount: 0.0,
                totalLateFee: 0.0,
                totalVacantHousingDiscount: 0.0,
                totalVacantHousingReduction: 0.0,
                totalNoDeduction: 0.0,
                totalCashDeduction: 0.0,
                totalPointDeduction: 0.0,
                totalDiscountCouponDeduction: 0.0,
                allPreferentialAmount: 0.0,
                allDeductionAmount: 0.0,
                allLateFee: 0.0,
                allVacantHousingDiscount: 0.0,
                allVacantHousingReduction: 0.0,
                allGiftAmount: 0.0,
                allNoDeduction: 0.0,
                allCashDeduction: 0.0,
                allPointDeduction: 0.0,
                allDiscountCouponDeduction: 0.0,
                totalGiftAmount: 0.0,
                conditions: {
                    floorId: '',
                    roomNum: '',
                    payerObjName: '', // 1-1-101
                    configId: '',
                    primeRate: '',
                    state: '',
                    feeTypeCd: '',
                    startTime: '',
                    endTime: '',
                    feeStartTime: '',
                    feeEndTime: '',
                    communityId: ''
                }
            }
        },
        _initMethod: function () {
            $that._listFeeDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            //与字典表支付方式关联
            vc.getDict('pay_fee_detail', "prime_rate", function (_data) {
                $that.adminPayFeeDetailInfo.primeRates = _data;
            });
            //与字典表费用状态关联
            vc.getDict('pay_fee_detail', "state", function (_data) {
                $that.adminPayFeeDetailInfo.states = _data;
            });
            //与字典表费用类型关联
            vc.getDict('pay_fee_config', "fee_type_cd", function (_data) {
                $that.adminPayFeeDetailInfo.feeTypeCds = _data;
            });
            vc.initDateTime('startTime',function(_value){
                $that.adminPayFeeDetailInfo.conditions.startTime = value;
            });
            vc.initDateTime('endTime',function(_value){
                $that.adminPayFeeDetailInfo.conditions.endTime = value;
            });
            vc.initDateTime('feeStartTime',function(_value){
                $that.adminPayFeeDetailInfo.conditions.feeStartTime = value;
            });
            vc.initDateTime('feeEndTime',function(_value){
                $that.adminPayFeeDetailInfo.conditions.feeEndTime = value;
            });
        },
        _initEvent: function () {
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listFeeDetails(_currentPage, DEFAULT_ROWS);
            });
            vc.on('selectAdminCommunity','changeCommunity',function(_community){
                $that.adminPayFeeDetailInfo.conditions.communityId = _community.communityId;
                $that._listFeeDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            })
        },
        methods: {
            //查询
            _queryMethod: function () {
                $that._listFeeDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //查询方法
            _listFeeDetails: function (_page, _rows) {
                $that.adminPayFeeDetailInfo.conditions.page = _page;
                $that.adminPayFeeDetailInfo.conditions.row = _rows;
                let param = {
                    params: $that.adminPayFeeDetailInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/fee.queryAdminPayFeeDetail',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.adminPayFeeDetailInfo.total = _json.total;
                        $that.adminPayFeeDetailInfo.records = _json.records;
                        $that.adminPayFeeDetailInfo.fees = _json.data;
                        $that.adminPayFeeDetailInfo.fees.forEach(item => {
                            item.lateFee = (item.lateFee * -1).toFixed(2);
                        })
                        if (typeof (_json.sumTotal.totalReceivableAmount) != 'undefined') {
                            $that.adminPayFeeDetailInfo.totalReceivableAmount = _json.sumTotal.totalReceivableAmount;
                        } else {
                            $that.adminPayFeeDetailInfo.totalReceivableAmount = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.totalReceivedAmount) != 'undefined') {
                            $that.adminPayFeeDetailInfo.totalReceivedAmount = _json.sumTotal.totalReceivedAmount;
                        } else {
                            $that.adminPayFeeDetailInfo.totalReceivedAmount = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.allReceivableAmount) != 'undefined') {
                            $that.adminPayFeeDetailInfo.allReceivableAmount = _json.sumTotal.allReceivableAmount;
                        } else {
                            $that.adminPayFeeDetailInfo.allReceivableAmount = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.allReceivedAmount) != 'undefined') {
                            $that.adminPayFeeDetailInfo.allReceivedAmount = _json.sumTotal.allReceivedAmount;
                        } else {
                            $that.adminPayFeeDetailInfo.allReceivedAmount = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.totalPreferentialAmount) != 'undefined') {
                            $that.adminPayFeeDetailInfo.totalPreferentialAmount = _json.sumTotal.totalPreferentialAmount;
                        } else {
                            $that.adminPayFeeDetailInfo.totalPreferentialAmount = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.totalNoDeduction) != 'undefined') {
                            $that.adminPayFeeDetailInfo.totalNoDeduction = _json.sumTotal.totalNoDeduction;
                        } else {
                            $that.adminPayFeeDetailInfo.totalNoDeduction = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.totalCashDeduction) != 'undefined') {
                            $that.adminPayFeeDetailInfo.totalCashDeduction = _json.sumTotal.totalCashDeduction;
                        } else {
                            $that.adminPayFeeDetailInfo.totalCashDeduction = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.totalPointDeduction) != 'undefined') {
                            $that.adminPayFeeDetailInfo.totalPointDeduction = _json.sumTotal.totalPointDeduction;
                        } else {
                            $that.adminPayFeeDetailInfo.totalPointDeduction = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.totalDiscountCouponDeduction) != 'undefined') {
                            $that.adminPayFeeDetailInfo.totalDiscountCouponDeduction = _json.sumTotal.totalDiscountCouponDeduction;
                        } else {
                            $that.adminPayFeeDetailInfo.totalDiscountCouponDeduction = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.totalDeductionAmount) != 'undefined') {
                            $that.adminPayFeeDetailInfo.totalDeductionAmount = _json.sumTotal.totalDeductionAmount;
                        } else {
                            $that.adminPayFeeDetailInfo.totalDeductionAmount = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.totalLateFee) != 'undefined' && _json.sumTotal.totalLateFee != 0.00) {
                            $that.adminPayFeeDetailInfo.totalLateFee = (_json.sumTotal.totalLateFee) * (-1);
                        } else {
                            $that.adminPayFeeDetailInfo.totalLateFee = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.totalVacantHousingDiscount) != 'undefined') {
                            $that.adminPayFeeDetailInfo.totalVacantHousingDiscount = _json.sumTotal.totalVacantHousingDiscount;
                        } else {
                            $that.adminPayFeeDetailInfo.totalVacantHousingDiscount = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.totalVacantHousingReduction) != 'undefined') {
                            $that.adminPayFeeDetailInfo.totalVacantHousingReduction = _json.sumTotal.totalVacantHousingReduction;
                        } else {
                            $that.adminPayFeeDetailInfo.totalVacantHousingReduction = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.allPreferentialAmount) != 'undefined') {
                            $that.adminPayFeeDetailInfo.allPreferentialAmount = _json.sumTotal.allPreferentialAmount;
                        } else {
                            $that.adminPayFeeDetailInfo.allPreferentialAmount = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.allDeductionAmount) != 'undefined') {
                            $that.adminPayFeeDetailInfo.allDeductionAmount = _json.sumTotal.allDeductionAmount;
                        } else {
                            $that.adminPayFeeDetailInfo.allDeductionAmount = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.allLateFee) != 'undefined' && _json.sumTotal.allLateFee != 0.00) {
                            $that.adminPayFeeDetailInfo.allLateFee = (_json.sumTotal.allLateFee) * (-1);
                        } else {
                            $that.adminPayFeeDetailInfo.allLateFee = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.allVacantHousingDiscount) != 'undefined') {
                            $that.adminPayFeeDetailInfo.allVacantHousingDiscount = _json.sumTotal.allVacantHousingDiscount;
                        } else {
                            $that.adminPayFeeDetailInfo.allVacantHousingDiscount = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.allVacantHousingReduction) != 'undefined') {
                            $that.adminPayFeeDetailInfo.allVacantHousingReduction = _json.sumTotal.allVacantHousingReduction;
                        } else {
                            $that.adminPayFeeDetailInfo.allVacantHousingReduction = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.allGiftAmount) != 'undefined') {
                            $that.adminPayFeeDetailInfo.allGiftAmount = _json.sumTotal.allGiftAmount;
                        } else {
                            $that.adminPayFeeDetailInfo.allGiftAmount = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.allNoDeduction) != 'undefined') {
                            $that.adminPayFeeDetailInfo.allNoDeduction = _json.sumTotal.allNoDeduction;
                        } else {
                            $that.adminPayFeeDetailInfo.allNoDeduction = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.allCashDeduction) != 'undefined') {
                            $that.adminPayFeeDetailInfo.allCashDeduction = _json.sumTotal.allCashDeduction;
                        } else {
                            $that.adminPayFeeDetailInfo.allCashDeduction = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.allPointDeduction) != 'undefined') {
                            $that.adminPayFeeDetailInfo.allPointDeduction = _json.sumTotal.allPointDeduction;
                        } else {
                            $that.adminPayFeeDetailInfo.allPointDeduction = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.allDiscountCouponDeduction) != 'undefined') {
                            $that.adminPayFeeDetailInfo.allDiscountCouponDeduction = _json.sumTotal.allDiscountCouponDeduction;
                        } else {
                            $that.adminPayFeeDetailInfo.allDiscountCouponDeduction = 0.0.toFixed(2);
                        }
                        if (typeof (_json.sumTotal.totalGiftAmount) != 'undefined') {
                            $that.adminPayFeeDetailInfo.totalGiftAmount = _json.sumTotal.totalGiftAmount;
                        } else {
                            $that.adminPayFeeDetailInfo.totalGiftAmount = 0.0.toFixed(2);
                        }
                        vc.emit('pagination', 'init', {
                            total: $that.adminPayFeeDetailInfo.records,
                            dataCount: $that.adminPayFeeDetailInfo.total,
                            currentPage: _page
                        });
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            //重置
            _resetMethod: function (_page, _rows) {
                $that._resetListFees(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _resetListFees: function (_page, _rows) {
                $that.adminPayFeeDetailInfo.conditions.floorId = "";
                $that.adminPayFeeDetailInfo.conditions.roomNum = "";
                $that.adminPayFeeDetailInfo.conditions.payerObjName = "";
                $that.adminPayFeeDetailInfo.conditions.primeRate = "";
                $that.adminPayFeeDetailInfo.conditions.startTime = "";
                $that.adminPayFeeDetailInfo.conditions.endTime = "";
                $that.adminPayFeeDetailInfo.conditions.feeStartTime = "";
                $that.adminPayFeeDetailInfo.conditions.feeEndTime = "";
                $that.adminPayFeeDetailInfo.conditions.configId = "";
                $that.adminPayFeeDetailInfo.conditions.state = "";
                $that.adminPayFeeDetailInfo.conditions.feeTypeCd = "";
                $that.adminPayFeeDetailInfo.feeConfigDtos = [];
                $that._listFeeDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.adminPayFeeDetailInfo.moreCondition) {
                    $that.adminPayFeeDetailInfo.moreCondition = false;
                } else {
                    $that.adminPayFeeDetailInfo.moreCondition = true;
                }
            },
            _exportFee: function () {
                //vc.jumpToPage('/callComponent/exportReportFee/exportData?pagePath=adminPayFeeDetail&' + vc.objToGetParam($that.adminPayFeeDetailInfo.conditions));
                //$that.adminPayFeeDetailInfo.conditions.communityId = vc.getCurrentCommunity().communityId;
                $that.adminPayFeeDetailInfo.conditions.pagePath = 'adminPayFeeDetail';
                let param = {
                    params: $that.adminPayFeeDetailInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/export.exportData', param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        vc.toast(_json.msg);
                        if (_json.code == 0) {
                            vc.jumpToPage('/#/pages/property/downloadTempFile?tab=下载中心')
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    });
            },
        }
    });
})(window.vc);